<% @page_title = "Profile" %>
<%= stylesheet_link_tag "default/common", :media => "all" %>
<%= stylesheet_link_tag "default/profile", :media => "all" %>
<script>
	$(document).ready(function(){
		$('span.edit').click(function(){
			var attr = $(this).attr('id');
			$('tr.'+attr).fadeOut(300);
			$('tr.edit_'+attr).fadeIn(300);
		});
		
		$('a.cancel').click(function(){
			var attr = $(this).attr('id');
			$('tr.'+attr).fadeIn(300);
			$('tr.edit_'+attr).fadeOut(300);
		})
	});
</script>
<div class="title"><span class="title_icon profile"><%=image_tag("login-icon.png") %></span>User profile</div>
<div class='clear'></div>

<div id="profile">
  <table cellspacing="5px" sellpadding="10px">
  	<tr class='fullname'>
      <th><label>Full Name</label></th>
      <td><%= @current_user.fullname %></td>
      <td><span id='fullname' class='edit'>Change</span></td>
    </tr>
    <tr class='edit edit_fullname'>
      <th><label>Full Name</label></th>
      <%= form_tag(:controller => 'default/user', :action => 'setting', :attr => 'fullname') do %>
      <td>
      	<%= text_field_tag :fullname, @current_user.fullname %><br /><br />
      	<%= submit_tag('Save') %>&nbsp;<a id='fullname' class='cancel action'>Cancel</a>	
      </td>
      <td></td>
      <% end %>
    </tr>
    <tr>
      <th><label>Username</label></th>
      <td><%= @current_user.username %></td>
      <td></td>
    </tr>
    <tr class='email'>
      <th><label>Email</label></th>
      <td><%= @current_user.email %></td>
      <td><span id='email' class='edit'>Change</span></td>
    </tr>
    <tr class='edit edit_email'>
      <th><label>Email</label></th>
      <%= form_tag(:controller => 'default/user', :action => 'setting', :attr => 'email') do %>
      <td>
      	<%= text_field_tag :email, @current_user.email %><br /><br />
      	<%= submit_tag('Save') %>&nbsp;<a id='email' class='cancel action'>Cancel</a>	
      </td>
      <td></td>
      <% end %>
    </tr>
    <tr>
      <th><label>Card ID</label></th>
      <td><%= @current_user.card_id %></td>
      <td></td>
    </tr>
    <tr>
      <th><label>Reader group</label></th>
      <td><%= @current_user.role.role_name %></td>
      <td></td>
    </tr>
    <tr>
      <th><label>Faculty</label></th>
      <td><%= @current_user.faculty.faculty_name %></td>
      <td></td>
    </tr>
    <tr>
      <th><label><% if @current_user.role_id == 1 %><%= "Student ID" %><% else %><%= "Teacher ID" %><% end %></label></th>
      <td><%= @current_user.reader_id %></td>
      <td></td>
    </tr>
    <tr class='phone'>
      <th><label>Phone</label></th>
      <td><%= @current_user.phone %></td>
      <td><span id='phone' class='edit'>Change</span></td>
    </tr>
    <tr class='edit edit_phone'>
      <th><label>Phone</label></th>
      <%= form_tag(:controller => 'default/user', :action => 'setting', :attr => 'phone') do %>
      <td>
      	<%= text_field_tag :phone, @current_user.phone %><br /><br />
      	<%= submit_tag('Save') %>&nbsp;<a id='phone' class='cancel action'>Cancel</a>	
      </td>
      <td></td>
      <% end %>
    </tr>
    <tr class="password">
      <th><label>Password</label></th>
      <td>********</td>
      <td><span id='password' class='edit'>Change</span></td>
    </tr>
    <tr class="edit edit_password">
      <td colspan="3">
        <%= form_tag(:controller => 'default/user', :action => 'setting', :attr => 'password') do %>
          <p><label class='sp'>Current password</label><%= password_field_tag :current_passw %></p>
          <p><label class='sp'>New password</label><%= password_field_tag :new_passw %></p>
          <p><label class='sp'>Confirm new password</label><%= password_field_tag :new_passw_confirm %></p>
          <p><label class='sp'>&nbsp;</label><%= submit_tag('Save') %>&nbsp;<a id='password' class='action cancel'>Cancel</a></p>
        <% end %>
      </td>
    </tr>
    <tr>
      <th><label>Created Date:</label></th>
      <td><%= @current_user.created_at %></td>
      <td></td>
    </tr>
  </table>
</div>

<div class='actions'>
	<%= link_to "Back", :controller => "default/book", :action => "index" %>
</div>

<div class="notice">
  <% if(flash[:notice]) %>
  	<div class="title"><span class="title_icon profile"><%=image_tag("login-icon.png") %></span>Notice</div>
	<div class='clear'></div>
    	<span class='notice'><%= flash[:notice] %></span>
  <% end %>
</div>